<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: PacManUI</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman.ui</a> ]
    </div>

    <h1>Coverage Summary for Class: PacManUI (nl.tudelft.jpacman.ui)</h1>

    <table class="coverageStats">
        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Class, %
            </th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">PacManUI</td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 1)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 4)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 24)
  </span>
            </td>
        </tr>

    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman.ui;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import java.awt.BorderLayout;
        <i>4</i>&nbsp;import java.awt.Container;
        <i>5</i>&nbsp;import java.util.Map;
        <i>6</i>&nbsp;import java.util.concurrent.Executors;
        <i>7</i>&nbsp;import java.util.concurrent.ScheduledExecutorService;
        <i>8</i>&nbsp;import java.util.concurrent.TimeUnit;
        <i>9</i>&nbsp;
        <i>10</i>&nbsp;import javax.swing.JFrame;
        <i>11</i>&nbsp;import javax.swing.JPanel;
        <i>12</i>&nbsp;import javax.swing.WindowConstants;
        <i>13</i>&nbsp;
        <i>14</i>&nbsp;import nl.tudelft.jpacman.game.Game;
        <i>15</i>&nbsp;import nl.tudelft.jpacman.ui.ScorePanel.ScoreFormatter;
        <i>16</i>&nbsp;
        <i>17</i>&nbsp;/**
        <i>18</i>&nbsp; * The default JPacMan UI frame. The PacManUI consists of the following
        <i>19</i>&nbsp; * elements:
        <i>20</i>&nbsp; *
        <i>21</i>&nbsp; * &lt;ul&gt;
        <i>22</i>&nbsp; * &lt;li&gt;A score panel at the top, displaying the score of the player(s).
        <i>23</i>&nbsp; * &lt;li&gt;A board panel, displaying the current level, i.e. the board and all units
        <i>24</i>&nbsp; * on it.
        <i>25</i>&nbsp; * &lt;li&gt;A button panel, containing all buttons provided upon creation.
        <i>26</i>&nbsp; * &lt;/ul&gt;
        <i>27</i>&nbsp; *
        <i>28</i>&nbsp; * @author Jeroen Roosen
        <i>29</i>&nbsp; */
        <b class="nc"><i>30</i>&nbsp;public class PacManUI extends JFrame {</b>
        <i>31</i>&nbsp;
        <i>32</i>&nbsp; /**
        <i>33</i>&nbsp; * Default serialisation UID.
        <i>34</i>&nbsp; */
        <i>35</i>&nbsp; private static final long serialVersionUID = 1L;
        <i>36</i>&nbsp;
        <i>37</i>&nbsp; /**
        <i>38</i>&nbsp; * The desired frame rate interval for the graphics in milliseconds, 40
        <i>39</i>&nbsp; * being 25 fps.
        <i>40</i>&nbsp; */
        <i>41</i>&nbsp; private static final int FRAME_INTERVAL = 40;
        <i>42</i>&nbsp;
        <i>43</i>&nbsp; /**
        <i>44</i>&nbsp; * The panel displaying the player scores.
        <i>45</i>&nbsp; */
        <i>46</i>&nbsp; private final ScorePanel scorePanel;
        <i>47</i>&nbsp;
        <i>48</i>&nbsp; /**
        <i>49</i>&nbsp; * The panel displaying the game.
        <i>50</i>&nbsp; */
        <i>51</i>&nbsp; private final BoardPanel boardPanel;
        <i>52</i>&nbsp;
        <i>53</i>&nbsp; /**
        <i>54</i>&nbsp; * Creates a new UI for a JPacman game.
        <i>55</i>&nbsp; *
        <i>56</i>&nbsp; * @param game The game to play.
        <i>57</i>&nbsp; * @param buttons The map of caption-to-action entries that will appear as
        <i>58</i>&nbsp; * buttons on the interface.
        <i>59</i>&nbsp; * @param keyMappings The map of keyCode-to-action entries that will be added as key
        <i>60</i>&nbsp; * listeners to the interface.
        <i>61</i>&nbsp; * @param scoreFormatter The formatter used to display the current score.
        <i>62</i>&nbsp; */
        <i>63</i>&nbsp; public PacManUI(final Game game, final Map&lt;String, Action&gt; buttons,
        <i>64</i>&nbsp; final Map&lt;Integer, Action&gt; keyMappings,
        <i>65</i>&nbsp; ScoreFormatter scoreFormatter) {
        <b class="nc"><i>66</i>&nbsp; super(&quot;JPacman &lt;2023-4-15&gt;&quot;);</b>
        <b class="nc"><i>67</i>&nbsp; assert game != null;</b>
        <b class="nc"><i>68</i>&nbsp; assert buttons != null;</b>
        <b class="nc"><i>69</i>&nbsp; assert keyMappings != null;</b>
        <i>70</i>&nbsp;
        <b class="nc"><i>71</i>&nbsp; setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);</b>
        <i>72</i>&nbsp;
        <b class="nc"><i>73</i>&nbsp; PacKeyListener keys = new PacKeyListener(keyMappings);</b>
        <b class="nc"><i>74</i>&nbsp; addKeyListener(keys);</b>
        <i>75</i>&nbsp;
        <b class="nc"><i>76</i>&nbsp; JPanel buttonPanel = new ButtonPanel(buttons, this);</b>
        <i>77</i>&nbsp;
        <b class="nc"><i>78</i>&nbsp; scorePanel = new ScorePanel(game.getPlayers());</b>
        <b class="nc"><i>79</i>&nbsp; if (scoreFormatter != null) {</b>
        <b class="nc"><i>80</i>&nbsp; scorePanel.setScoreFormatter(scoreFormatter);</b>
        <i>81</i>&nbsp; }
        <i>82</i>&nbsp;
        <b class="nc"><i>83</i>&nbsp; boardPanel = new BoardPanel(game);</b>
        <i>84</i>&nbsp;
        <b class="nc"><i>85</i>&nbsp; Container contentPanel = getContentPane();</b>
        <b class="nc"><i>86</i>&nbsp; contentPanel.setLayout(new BorderLayout());</b>
        <b class="nc"><i>87</i>&nbsp; contentPanel.add(buttonPanel, BorderLayout.SOUTH);</b>
        <b class="nc"><i>88</i>&nbsp; contentPanel.add(scorePanel, BorderLayout.NORTH);</b>
        <b class="nc"><i>89</i>&nbsp; contentPanel.add(boardPanel, BorderLayout.CENTER);</b>
        <i>90</i>&nbsp;
        <b class="nc"><i>91</i>&nbsp; pack();</b>
        <i>92</i>&nbsp; }
        <i>93</i>&nbsp;
        <i>94</i>&nbsp; /**
        <i>95</i>&nbsp; * Starts the &quot;engine&quot;, the thread that redraws the interface at set
        <i>96</i>&nbsp; * intervals.
        <i>97</i>&nbsp; */
        <i>98</i>&nbsp; public void start() {
        <b class="nc"><i>99</i>&nbsp; setVisible(true);</b>
        <b class="nc"><i>100</i>&nbsp; ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();</b>
        <b class="nc"><i>101</i>&nbsp; service.scheduleAtFixedRate(this::nextFrame, 0, FRAME_INTERVAL,
            TimeUnit.MILLISECONDS);</b>
        <i>102</i>&nbsp; }
        <i>103</i>&nbsp;
        <i>104</i>&nbsp; /**
        <i>105</i>&nbsp; * Draws the next frame, i.e. refreshes the scores and game.
        <i>106</i>&nbsp; */
        <i>107</i>&nbsp; private void nextFrame() {
        <b class="nc"><i>108</i>&nbsp; boardPanel.repaint();</b>
        <b class="nc"><i>109</i>&nbsp; scorePanel.refresh();</b>
        <i>110</i>&nbsp; }
        <i>111</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
